#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 11;

/*
the question is changing the sudoku to anti-sudoku
the anti-sudoku satisfies the condition below
1: any number in this field is in range[1:9]
2: each row and colunm contains at least two equal elements
3: 3 * 3 block contains at least two equal elements

we can change [1, 1], [2, 4], [3, 7], [4, 2], [5, 5], [6, 8], [7, 3], [8, 6], [9, 9] into other number to reach the condition

*/

int g[N][N];

int f(int x){
    return x % 9 + 1;
}

void solve(){
    for(int i = 1; i <= 9; i ++){
        string s;
        cin >> s;
        for(int j = 1; j <= 9; j ++){
            g[i][j] = s[j - 1] - '0';
        }
    }

    g[1][1] = f(g[1][1]);
    g[2][4] = f(g[2][4]);
    g[3][7] = f(g[3][7]);
    g[4][2] = f(g[4][2]);
    g[5][5] = f(g[5][5]);
    g[6][8] = f(g[6][8]);
    g[7][3] = f(g[7][3]);
    g[8][6] = f(g[8][6]);
    g[9][9] = f(g[9][9]);

    for(int i = 1; i <= 9; i ++){
        for(int j = 1; j <= 9; j ++){
            cout << g[i][j];
        }
        cout << '\n';
    }

}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        solve();
    }
    return 0;
}